<?php 

/**
 * 个人中心控制器
 * @author 妮妮 <962611024@qq.com>
 */
class MyaddController extends Controller{
	private $model;
	private $ress;
	public function __init(){
		$this->model=K('Userself');
		$this->ress=K('Address');
	}
    /**
     * 默认访问方法
     */
    public function index(){
    	$uid=$_SESSION['uid'];
		$_POST['uid']=$uid;
		$selfData=M('userself')->where("uid={$uid}")->find();
		$this->assign('selfData',$selfData);
    	if(IS_POST){
			$upload=new Upload("Upload/selfFace");
			$uplofiles =$upload->upload();
			//p($uplofiles);die;
			$path=isset($uplofiles[0]['path'])?$uplofiles[0]['path']:$selfData['face'];
			$_POST['face']=$path;
			if(!$this->model->uselfAdd()) $this->error($this->model->error);
			//判断修改的时候把原图删掉
			if(!empty($selfData['face'])){
//				移除头像图片（face图片）
				unlink($selfData['face']);
			}
			$this->success('保存成功');
    	}
		//获取旧的数据，分配出去 方便修改
		
		
		
        $this->display(); 
    }
	
	
	/*
	 * 我的收货地址
	 * */
	public function location(){
		$uid=$_SESSION['uid'];
		$_POST['uid']=$uid;
		if(IS_POST){
    		if(!$this->ress->ressAdd()) $this->error($this->model->error);
			//$this->success('添加成功');
    	}
		$ressData=M('address')->where("uid={$uid}")->find();
		$this->assign('ressData',$ressData);
		
		
	    $this->display();
	}
	/*
	 * 删除地址
	 * */
	public function locationDel(){
		$aid=Q('get.aid',0,'intval');
		$this->ress->where("aid={$aid}")->delete();
		$this->success("删除成功！");
	}
	/*
	 * 已购买的商品
	 * */
	public function myself(){
	    $this->display();
	}
	
	
 }
 
 
 
 
 
 
 
 
 
 
 





















 ?>